//
//  GlobalUtil.h
//  Wanna
//
//  Created by apple on 15/4/10.
//  Copyright (c) 2015年 apple. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <SDWebImageManager.h>
#import "MBProgressHUD+NJ.h"

static NSString *const nHomePageRefresh = @"homePageRefresh";
static NSString *const nOrderPageRefresh = @"orderPageRefresh";
static NSString *const nGoodsManagementRefresh = @"goodsManagementRefresh";


@interface GlobalUtil : NSObject


//验证手机号是否合法
+ (BOOL) validateMobile:(NSString *)mobile;

//密码
+ (BOOL) validatePassword:(NSString *)passWord;

//邮箱
+ (BOOL) validateEmail:(NSString *)email;

//金额输入验证
+(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string;

//昵称
+ (BOOL) validateNickname:(NSString *)nickname;

//只输入数字
+ (BOOL) validateNumOnly:(NSString *)inputStr digits:(int)digit;

//只输入字母或数字
+ (BOOL) validateNumAndStringOnly:(NSString *)inputStr digits:(int)digit;

//用户名;
+ (BOOL) validateUserName:(NSString *)name;
//字符串编码转换
+(NSString *)changeUrlToUTF:(NSString *)nurl;

//计算文件大小
+(long long)fileSizeAtPath:(NSString*) filePath;

//计算文件夹大小
+(float) folderSizeAtPath:(NSString*) folderPath;

//身份证号
+ (BOOL) validateIdentityCard: (NSString *)identityCard;

//显示toast
+ (MBProgressHUD*)HUDShowMessage:(NSString*)msg addedToView:(UIView*)view;

+ (MBProgressHUD *)HUDShowLoadingInView:(UIView *)view;

+ (MBProgressHUD*)HUDShowMessage:(NSString*)msg addedToView:(UIView*)view completionBlock:(void(^)())block;


/**
 *  AWU专用：根据页面是否已经加载了数据，显示不同的错误提示：错误页or错误提示
 *
 *  @param isLoadData 监测值：是否已经加载数据
 *  @param view       所在view
 *  @param msg        错误提示
 *  @param block      错误页的刷新按钮执行block
 */
+(void)showErrorObservingValue:(BOOL)isLoadData onView:(UIView *)view errorMsg:(NSString *)msg retryBlock:(void (^)())block;
//自定义navagition item
+ (UIBarButtonItem*)createBarButtonItemWithTitle:(NSString*)buttonTitle target:(id)target action:(SEL)action;

//自定义navagition item
+ (UIBarButtonItem*)createBarButtonItemWithImage:(NSString*)imageNa target:(id)target action:(SEL)action tag:(NSInteger)tag;

//缩放UIImage
+ (UIImage*)scaleImage:(UIImage*)image toNewSize:(CGSize)size;

+ (UIImage *)blurryImage:(UIImage *)image withBlurLevel:(CGFloat)blur;

//从URL获取图片（缓存版）
+ (void)downloadImageWithURLCache:(NSString*)url completed:(SDWebImageCompletionBlock)completedBlock;

//将钱从分转成元及字符串，自动判断是否应该有小数
+ (NSString*)getMoneyString:(NSInteger)money;

#pragma mark - 清理集合（Array & Dictionary）中的NSNull
+ (void)deepCleanCollection:(id<NSFastEnumeration>)collection;
//图片压缩
+ (UIImage *)scaleToSize:(UIImage *)img size:(CGSize)size;

//修改图片的颜色：
+ (UIImage *)sectionImage:(UIImage*)image withTintColor:(UIColor*)color;

//计算字符串高度
+ (float) heightForString:(NSString *)value fontSize:(float)fontSize andWidth:(float)width;

//需要用户登录，才能push页面
+(void)pushPageWithLoginNeed:(UIViewController *)currentVC toViewController:(UIViewController *)toVC;

//需要用户登录，才能执行block
+(void)checkLoginNeedWithBlock:(void (^)())block;

//判断NSString是否空值
+ (BOOL)isNilValue:(NSString *)value;

/**
 *  删除tableview中其他元素点击效果滞后的
 *
 *  @param tableview 需要更改效果的tableview
 */
+(void)removeDelaysofContentTouches:(UITableView*)tableview;

/**
 *  给tableview 的section 添加grouped style, 在tableview 的 willDisplayCell 方法中调用，将tableview,cell,indexpath 直接传入即可
 *
 *  @param tableView tableview need add grouped style
 *  @param cell      cell need add grouped style
 *  @param indexPath indexpath need add grouped style
 *  @param color     border color
 */
+ (void)addGroupedStyletoSection:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath withBorderColor:(UIColor*)color;

// 修改图片size
+ (UIImage *)image:(UIImage*)image byScalingToSize:(CGSize)targetSize;

// 判断用户会员是否过期
+ (BOOL)memberVipIsOverDue;

//时间戳转时间
+(NSString *)setUpTime:(NSString *)time;


//present登录页面
+ (void)presentLoginVC;

//根据内容计算label高度
+ (CGFloat)getLabelHeightWithContent:(NSString *)content
                         fontSize:(CGFloat)size
                       labelWidth:(CGFloat)width;



@end
